<?php
//
//	file: installer/inc_cash.php
//	begin: 08/05/2007
//	$Author: christopher $
//	$Revision: 27 $
//	$Date: 2008-01-28 22:20:14 +0000 (Mon, 28 Jan 2008) $
//	license: http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)

if ( !defined('IN_PHPBB') || !defined('IN_INSTALL') )
{
	die('Hack attempt !');
	exit;
}

class cash_install
{
	function cash_install()
	{
		global $parms_def;

		// includes
		include($config->url('includes/cash/class_cash'));
		lang_include('lang_CH_install_cash');

		// parms (not set is : type => TYPE_INT, default => 0)
		$parms_def += array(
			'capv' => array('type' => TYPE_NO_HTML, 'default' => ''),
			'cand' => array('type' => TYPE_INT, 'default' => 0),
			'camd' => array('type' => TYPE_INT, 'default' => 0),
		);

		return;
	}

	function start()
	{
		global $part_script, $page;

		// parms (not set is : type => TYPE_INT, default => 0)
		$part_script[] = sprintf($page->lang('CA_welcome_explain'), CASH_CURRENT_VERSION);

		return;
	}

	function prev_vers()
	{
		global $db, $page, $parms;

		// check
		$parms['capv'] = '';

		// current line
		$sql = 'SELECT config_value
					FROM ' . CONFIG_TABLE . '
					WHERE config_name = \'mod_cash\'';
		$result = $db->sql_query($sql, false, __LINE__, __FILE__);
		if ( $row = $db->sql_fetchrow($result) )
		{
			$parms['capv'] = $row['config_value'];
		}
		$db->sql_freeresult($result);

		// standalone line
		if ($parms['capv'] == '')
		{
			$sql = 'SELECT config_value
						FROM ' . CONFIG_TABLE . '
						WHERE config_name = \'cash_version\'';
			if ( $result = $db->sql_query($sql, false, __LINE__, __FILE__) )
			{
				$parms['capv'] = ($row = $db->sql_fetchrow($result)) ? '0.9.0' : false;
			}
			$db->sql_freeresult($result);
		}

		if ($parms['capv'])
		{
			$page->output(sprintf($page->lang('CA_previous_version',$parms['capv'])));
		}

		return;
	}
	function db()
	{
		global $parms;

		$parms['cand'] = $parms['camd'] = false;

		// install schema
		switch ( $parms['capv'] )
		{
			case '0.9.0':
				$schemas[] = 'cash_100';
				$parms['camd'] = true;
				break;
			default:
				$schemas[] = 'cash_ch';
				$parms['cand'] = true;
				break;
		}
		return;
	}

	function migrate()
	{
		global $page, $db, $config, $parms;

		if (!$parms['camd'])
		{
			return;
		}

		$this->up_100();

		$page->output('CA_migrate_succeed');

		return;
	}

	function up_100()
	{
		global $page, $db, $config, $parms;

		$config->set('cash_spam_num', $config->data['cash_disable_spam_num'], true);
		$config->set('cash_spam_time', $config->data['cash_disable_spam_time'], true);
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
				WHERE config_name = \'cash_installed\'';
		$db->sql_query($sql, false, __LINE__, __FILE__);
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
				WHERE config_name = \'cash_version\'';
		$db->sql_query($sql, false, __LINE__, __FILE__);
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
				WHERE config_name = \'cash_adminnavbar\'';
		$db->sql_query($sql, false, __LINE__, __FILE__);
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
				WHERE config_name = \'cash_adminbig\'';
		$db->sql_query($sql, false, __LINE__, __FILE__);
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
				WHERE config_name = \'cash_disable_spam_message\'';
		$db->sql_query($sql, false, __LINE__, __FILE__);
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
				WHERE config_name = \'points_name\'';
		$db->sql_query($sql, false, __LINE__, __FILE__);
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
				WHERE config_name = \'cash_disable_spam_time\'';
		$db->sql_query($sql, false, __LINE__, __FILE__);
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
				WHERE config_name = \'cash_disable_spam_num\'';
		$db->sql_query($sql, false, __LINE__, __FILE__);
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
				WHERE config_name = \'cash_display_after_posts\'';
		$db->sql_query($sql, false, __LINE__, __FILE__);
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
				WHERE config_name = \'cash_disable\'';
		$db->sql_query($sql, false, __LINE__, __FILE__);
	}

	function init_data()
	{
		global $db, $page, $parms, $config, $cash;

		if ( !$parms['cand'] )
		{
			return;
		}

		$config->set('cash_spam_num', $config->data['cash_disable_spam_num'], true);
		$config->set('cash_spam_time', $config->data['cash_disable_spam_time'], true);
		$config->set('cash_disable', true, true);

		return;
	}

	function patch()
	{
		global $config;

		$config->set('mod_cash', CASH_CURRENT_VERSION, true);

		return;
	}

	function fin()
	{
		global $page, $parms;

		$page->output(empty($parms['capv']) ? 'CA_install_done' : 'CA_install_upgraded');

		return;
	}
}

$parts[] = 'cash_install';

?>